#include "TopicsRateSerializer.h"

TopicsRateSerializer::~TopicsRateSerializer()
{
	topicsHz_.clear();
}

int TopicsRateSerializer::serialize(int messageType, char * message)
{
	return 0;
}

int TopicsRateSerializer::deseralize(int messageType, const std::string & message)
{
	rapidjson::Document doc;
	doc.Parse(message.c_str());
	assert(doc.IsObject());

	rapidjson::Value& topics_hz = doc["topics_hz"];
	for (int i = 0; i < topics_hz.Size(); i++)
	{
		TopicHz topichz;
		topichz.name = topics_hz[i]["name"].GetString();
		topichz.rate = topics_hz[i]["rate"].GetDouble();
		topichz.min_delay = topics_hz[i]["min_delay"].GetDouble();
		topichz.max_delay = topics_hz[i]["max_delay"].GetDouble();
		topichz.std_dev = topics_hz[i]["std_dev"].GetDouble();
		topichz.window = topics_hz[i]["window"].GetInt();

		topicsHz_.push_back(topichz);
	}
	return 0;
}
